<?php
session_start();
error_reporting(0);
$isadmin=1;
$adminusername=$_SESSION["adminusername"]; 
if($adminusername==NULL)
{
	echo "错误：登录超时，请<a href=login.php target=_parent>重新登录</a>！";
	exit;
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body><?php
$dir='../.'; 
$jumpoff=false;
$jump='bbs|admin|/|phpzip.inc.php|savetaobaokesetting.php|savewebsetting.php|taobaokeset.php|top.php|webset.php|class.phpmailer.php|Taoapi_Util.php|phpzip.lib.php|JSON.php|client.php|base.php|scan.php|Apicache|config.php|step-3.php|center.php|mall.php'; 
$danger='eval|cmd|passthru|CreateObject';
$suffix='php|inc|asp';
$dir_num=0;
$file_num=0;
$danger_num=0;

extract (GetHttpVars());

if ($m=="edit") Edit();
if ($m=="del") Delete();
if ($check=='check')
{   $safearr = explode("|",$jump);
$start_time=microtime(true);
safe_check($dir);
$end_time=microtime(true);
$total=$end_time-$start_time;
$file_num=$file_num-$dir_num;
if($danger_num==0){echo "<br><font color=#009900>没有扫描到可疑文件！</font><br><br>";}
$message= "<br> 文件数:".$file_num."<br>";
$message.= " 文件夹数：".$dir_num."<br>";
$message.= " 可疑文件数：<font color=#ff0000>".$danger_num."</font><br>";
$message.= " 执行时间：".$total."<br><br><font color=#ff0000>注意：本次扫描结果仅作参考。请先查看代码确认属非法文件再做删除处理。</font>";
echo $message;
exit();
}
function GetHttpVars() {//全局变量
$superglobs = array(
'_POST',
'_GET',
'HTTP_POST_VARS',
'HTTP_GET_VARS');
$httpvars = array();

foreach ($superglobs as $glob) {
   global $$glob;
   if (isset($$glob) && is_array($$glob)) {
    $httpvars = $$glob;
   }
   if (count($httpvars) > 0)
   break;
}
return $httpvars;

}
function Safe_Check($dir)//遍历文件
{
global $danger ,$suffix ,$dir_num ,$file_num ,$danger_num;
$dirarr = explode("|",$dir);
foreach ($dirarr as $subdir) {
	$hand=@dir($subdir) or die('文件夹不存在') ;
	while ($file=$hand->read() )
	{
	   $filename=$subdir.'/'.$file;
	   if (!$jumpoff) {
		if(Jump($filename))continue;
	   }
	   if(@is_dir($filename) && $file != '.' && $file!= '..'&& $file!='./..')
	   {   $dir_num++;
	   Safe_Check($filename);
	   }
	   if (preg_match_all ("/\.($suffix)/i",$filename,$out))
	   {
	
		$str='';
		$fp = @fopen($filename,'r')or die('没有权限');
		while(!feof($fp))
		{
		 $str .= fgets($fp,1024);
		}
		fclose($fp);
		if( preg_match_all ("/($danger)[ \r\n\t]{0,}([\[\(])/i",$str,$out))
		{$fname=str_replace("../","",$filename);
		 echo "<font color='green' style='font-size:14px'>可疑文件：{$fname}</font>
			   <a href='?m=edit&filename=$filename' target='_blank'><u>查看代码</u></a>
			   <a href='?m=del&filename=$filename' target='_blank'>删除</u></a><br>";
		 $danger_num++;
		}
   	}

   $file_num++;
}
}
}
function Edit()//查看可疑文件
{
global $filename;
$filename = str_replace("","",$filename);
$file = $filename;
$content = "";
if(is_file($file))
{
   $fp = fopen($file,"r")or die('没有权限');
   $content = fread($fp,filesize($file));
   fclose($fp);
   $content = htmlspecialchars($content);

}
echo "<textarea name='str' style='width:100%;height:450px;background:#cccccc;'>$content</textarea>\r\n";
exit();
}
function Delete()//删除文件
{
global $filename;
(is_file($filename))?($mes=unlink($filename)?'删除成功':'删除失败 查看权限'):'';
echo $mes;
exit();
}
function Jump($file)//跳过文件
{
global $jump,$safearr;
if($jump != '')
{
   foreach($safearr as $v)
   {
    if($v=='') continue;
    if( eregi($v,$file) ) return true ;
   }
}
return false;
}
?>
<div style="width:100%; margin:100px auto; text-align:center">
<div style="width:420px; height:50px; line-height:50px; font-size:20px; font-weight:bold; color:#990000; text-align:center; margin:0 auto">多多返利系统专用木马查杀器 V1.0</div>
<form action="" >
<input type="submit" value="马上开始检测" />
<input type="hidden" name="check"   value="check"/>
</form>
<div style="border:1px solid #ddd; margin:20px auto; color:#FF0000; font-size:12px; text-align:left; width:420px; height:150px; line-height:30px; padding:20px;">多多返利系统专用木马查杀器 V1.0，将对您站内的程序文件进行扫描。本系统提供了查看代码和删除操作。<br>如有疑问或建议请提交论坛， <a href="http://bbs.duoduo123.com/thread-htm-fid-71.html" target="_blank">立即提交</a></div>
</div></body>
</html>